package com.siki.Config.JsonConfig;

import lombok.Getter;

@Getter
public enum GlobalServiceMsgCode {
    /* 成功 */
    SUCCESS(200, "成功"),

    /* 默认失败 */
    COMMON_FAIL(999, "失败"),

    /* 参数错误：1000～1999 */
    PARAM_NOT_VALID(1001, "参数无效"),
    PARAM_IS_BLANK(1002, "参数为空"),
    PARAM_TYPE_ERROR(1003, "参数类型错误"),
    PARAM_NOT_COMPLETE(1004, "参数缺失"),

    /* 定义返回信息 */
    SERVICE_SUCCESS(0, "操作成功"),
    SERVICE_FAIL(1111, "操作失败"),

    /* 异常 */
    ERROR_FAIL(9999,"异常");

    private Integer code;
    private String message;

    GlobalServiceMsgCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }


    /**
     * 根据code获取message
     *
     * @param code
     * @return
     */
    public static String GlobalServiceMsgCode(Integer code) {
        for (GlobalServiceMsgCode ele : values()) {
            if (ele.getCode().equals(code)) {
                return ele.getMessage();
            }
        }
        return null;
    }
}